﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.IO;
using SiteECSWeb;
using System.Text;
using System.Security.Cryptography;

public partial class SiteTemplate : MasterBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            CTopMenuSiteMapDataSource.SiteMapProvider =
                SiteMapProviderNames.TopSubMXmlSiteMapProvider.ToString();
            BMSiteMapDataSource.SiteMapProvider =
                SiteMapProviderNames.BMenuXmlSiteMapProvider.ToString();
            CBottomMenuSiteMapDataSource.SiteMapProvider =
                SiteMapProviderNames.BottomSubMXmlSiteMapProvider.ToString();

            #region BadOnce
            if (Page.User.Identity.IsAuthenticated)
            {
                HyperLink hylkCompEditProfile = LoginView1.FindControl("hylkCompEditProfile") as HyperLink;
                HyperLink hylkECSEditProfile = LoginView1.FindControl("hylkECSEditProfile") as HyperLink;
                HyperLink hylkOfficeData = LoginView1.FindControl("hylkOfficeData") as HyperLink;
                HyperLink hylkOfficeSticsData = LoginView1.FindControl("hylkOfficeSticsData") as HyperLink;
                HyperLink hylkDepSticsData = LoginView1.FindControl("hylkDepSticsData") as HyperLink;

                if (hylkCompEditProfile != null)
                {
                    if (Page.User.IsInRole(RolesName.Companies.ToString()) ||
                        Page.User.IsInRole(RolesName.NewUsers.ToString()))
                    {
                         hylkCompEditProfile.NavigateUrl =
                        Helper.NavURLParamsStringVirtualName(Page.User.Identity.Name,
                        Globals.Settings.VirtualNamesInfo.CompanyAccountEdit);
                    }
                   
                }
                if (hylkECSEditProfile != null)
                {
                    if (Page.User.IsInRole(RolesName.AdminSystem.ToString()) ||
                        Page.User.IsInRole(RolesName.ECSInternal.ToString()) ||
                        Page.User.IsInRole(RolesName.SysAdmin.ToString()) ||
                        Page.User.IsInRole(RolesName.NewEcs.ToString()))
                    {
                        hylkECSEditProfile.NavigateUrl =
                      Helper.NavURLParamsStringVirtualName(Page.User.Identity.Name,
                      Globals.Settings.VirtualNamesInfo.EmployeeAccountEdit);
                    }
                }
                if (hylkOfficeData != null)
                {
                    if (Page.User.IsInRole(RolesName.Offices.ToString()))
                    {
                        EcsOfficeBLL offAPI = new EcsOfficeBLL();
                        EcsSiteDS.EcsOfficDataTable offTable =
                            offAPI.GetEcsOfficeByEmail(Membership.GetUser(Page.User.Identity.Name).Email);
                        if (offTable.Count != 0)
                        {
                            EcsSiteDS.EcsOfficRow offrow = offTable[0];
                            hylkOfficeData.NavigateUrl =
                                Helper.NavURLParamsStringVirtualName(offrow.City_nmen,
                                Globals.Settings.VirtualNamesInfo.OfficeEdit, true);
                            hylkOfficeSticsData.NavigateUrl =
                                Helper.NavURLParamsStringVirtualName(offrow.City_nmen,
                                Globals.Settings.VirtualNamesInfo.OfficeStics, true);
                        }
                    }
                }
                if (hylkDepSticsData != null)
                {
                    if (Page.User.IsInRole(RolesName.Departments.ToString()))
                    {
                        DeprtCategoryBLL depAPI = new DeprtCategoryBLL();
                        EcsSiteDS.DepCategoryDataTable depTable =
                            depAPI.GetDepCategoryByEmail(Membership.GetUser(Page.User.Identity.Name).Email);
                        if (depTable.Count != 0)
                        {
                            EcsSiteDS.DepCategoryRow deprow = depTable[0];
                            hylkDepSticsData.NavigateUrl =
                                Helper.NavURLParamsStringVirtualName(deprow.DepCat_NameEn,
                                Globals.Settings.VirtualNamesInfo.DepStics, true);
                        }
                    }
                }
            }
            #endregion
        }
        Page.Header.DataBind();
    }
}

